package com.xzz.experiment.QinGongJianXue;

import java.util.ArrayList;
import java.util.Scanner;

public class D1 {
    final static int YouXiu = 500;
    final static int JiGe = 300;
    final static int BuJige = 50;

    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<Student>();
        ArrayList<Ex> exs = new ArrayList<Ex>();
        ex(exs);//添加实验室
        while (true) {
            System.out.println("------欢迎使用勤工俭学系统------");
            System.out.println("------1.添加学生并选择实验室----");
            System.out.println("------2.教师评分--------------");
            System.out.println("------3.学生工资--------------");
            System.out.println("------4.学生清洁记录-----------");

            Scanner sc = new Scanner(System.in);
            String line = sc.nextLine();
            switch (line) {
                case "1":
                    addStudent(students, exs);//添加学生并选择实验室
                    break;
                case "2":
                    grade(exs);//教师评分
                    break;
                case "3":
                    salary(students, exs);//学生工资
                    break;
                case "4":
                    record(students, exs);//学生清洁记录
            }
        }
    }

    public static void addStudent(ArrayList<Student> array, ArrayList<Ex> e) {//添加学生方法
        Scanner sc = new Scanner(System.in);
        //为了让sid在while循环外面被访问到，我们就把它定义在循环的外面
        String id;
        while (true) {
            System.out.println("请输入学生学号：");
            id = sc.nextLine();//sid接收信息
            boolean flag = isUsed(array, id);//调用isused方法进行判断
            if (flag) {
                System.out.println("你输入的学号已经被使用，请重新输入");
            } else
                break;
        }
        System.out.println("请输入学生姓名：");
        String name = sc.nextLine();

        System.out.println("请输入学生年龄：");
        String age = sc.nextLine();

        Student st1 = new Student();
        //创建学生对象，把键盘录入的数据赋值给学生对象的成员变量
        st1.setId(id);
        st1.setName(name);
        st1.setAge(age);

        System.out.println("可选择实验室如下所示：");
        for (int i = 0; i < e.size(); i++) {
            Ex ex = e.get(i);
            System.out.println(i + 1 + "." + ex.toString());
        }
        System.out.println("你想要选择清理几个实验室：");
        int a = sc.nextInt();
        int[] b = new int[a];
        for (int i = 0; i < a; i++) {
            int c = i + 1;
            System.out.println("请选择第" + c + "个实验室");
            int line = sc.nextInt();
            b[i] = line;
        }
        st1.setXk(b);
        //将学生对象添加到集合中
        array.add(st1);

        System.out.println("添加成功");

    }

    public static boolean isUsed(ArrayList<Student> array, String sid) {//定义一个方法判断学号是否被占用
        boolean flag = false;
        for (int i = 0; i < array.size(); i++) {//集合的遍历
            Student s = array.get(i);
            if (s.getId().equals(sid)) {//equals：字符串的比较方法
                flag = true;
                break;
            }
        }
        return flag;
    }

    public static void ex(ArrayList<Ex> e) {//添加实验室
        Ex ex1 = new Ex("计算机网络实验室", "综1101");
        Ex ex2 = new Ex("组成原理实验室", "综1102");
        Ex ex3 = new Ex("单缝衍射实验室", "综1103");
        Ex ex4 = new Ex("声速测定实验室", "综1104");
        Ex ex5 = new Ex("伏安法测电阻实验室", "综1105");
        e.add(ex1);
        e.add(ex2);
        e.add(ex3);
        e.add(ex4);
        e.add(ex5);
    }

    public static void grade(ArrayList<Ex> e) {//评分
        int[] a = new int[5];//五周
        int[] b = new int[5];
        int[] c = new int[5];
        int[] d = new int[5];
        int[] g = new int[5];
        int f;
        Scanner sc = new Scanner(System.in);
        System.out.println("需要评分的实验室如下所示：");
        for (int i = 0; i < e.size(); i++) {
            Ex ex = e.get(i);
            System.out.println(i + 1 + "." + ex.toString());
        }
        System.out.println("（优秀输入“1”，及格输入“2”，不及格输入“3”需按照上述顺序评分）");


//重新设置实验室信息
        System.out.println("第" + 1 + "个实验室：");
        Ex ex1 = e.get(0);
        for (int j = 0; j < 5; j++) {
            f = sc.nextInt();
            a[j] = f;
        }
        ex1.setAddress("综1101");
        ex1.setName("计算机网络实验室");
        ex1.setSalary(a);
        e.set(0, ex1);

        System.out.println("第" + 2 + "个实验室：");
        Ex ex2 = e.get(1);
        for (int j = 0; j < 5; j++) {
            f = sc.nextInt();
            b[j] = f;
        }
        ex2.setAddress("综1102");
        ex2.setName("组成原理实验室");
        ex2.setSalary(b);
        e.set(1, ex2);

        System.out.println("第" + 3 + "个实验室：");
        Ex ex3 = e.get(2);
        for (int j = 0; j < 5; j++) {
            f = sc.nextInt();
            c[j] = f;
        }
        ex3.setAddress("综1103");
        ex3.setName("单缝衍射实验室");
        ex3.setSalary(c);
        e.set(2, ex3);

        System.out.println("第" + 4 + "个实验室：");
        Ex ex4 = e.get(3);
        for (int j = 0; j < 5; j++) {
            f = sc.nextInt();
            d[j] = f;
        }
        ex4.setAddress("综1104");
        ex4.setName("声速测定实验室");
        ex4.setSalary(d);
        e.set(3, ex4);

        System.out.println("第" + 5 + "个实验室：");
        Ex ex5 = e.get(4);

        for (int j = 0; j < 5; j++) {
            f = sc.nextInt();
            g[j] = f;
        }
        ex5.setAddress("综1105");
        ex5.setName("伏安法测电阻实验室");
        ex5.setSalary(g);
        e.set(4, ex5);
        System.out.println("评分已完成");
    }

    public static void salary(ArrayList<Student> s, ArrayList<Ex> e) {//计算工资
        int[] a, b;
        int h;

        for (int i = 0; i < s.size(); i++) {
            Student s1 = s.get(i);
            System.out.println("学号" + "\t" + "年龄" + "\t" + "姓名");
            System.out.println(s1.getId() + "\t" + s1.getAge() + "\t" + s1.getName());
            a = s1.getXk();
            int sum = 0;
            double sum1 = 0.0f;
            for (int j = 0; j < a.length; j++) {//循环位次
                for (int c = 1; c < 6; c++) {//循环实验室选项
                    if (a[j] == c) {
                        h = c - 1;
                        Ex ex = e.get(h);
                        b = ex.getSalary();
                        for (int k = 0; k < b.length; k++) {
                            if (b[k] == 1) {
                                sum += YouXiu;
                            }
                            if (b[k] == 2) {
                                sum += JiGe;
                            }
                            if (b[k] == 3) {
                                sum += BuJige;
                            }
                        }
                    }
                }
            }
            System.out.println("税前工资为：" + sum);//计算税后工资
            if (sum <= 5000) {
                sum1 = sum;
            }
            if (sum > 5000 && sum <= 8000) {
                sum1 = sum - (sum * 0.03);
            }
            if (sum > 8000 && sum <= 17000) {
                sum1 = sum - (sum * 0.1);
            }
            System.out.println("税后工资为：" + sum1);//输出工资
        }
    }

    public static void record(ArrayList<Student> array, ArrayList<Ex> e) {//记录
        int[] a;
        String s1 = "0";
        while (true) {
            System.out.println("请输入需要查询的学生的学号(输入“0”退出记录查询)");
            Scanner sc = new Scanner(System.in);
            String line = sc.nextLine();
            if (line.equals(s1)) {//判断是否输入”0“，输入则退出循环
                break;
            }
            for (int i = 0; i < array.size(); i++) {
                Student s = array.get(i);
                if (s.getId().equals(line)) {
                    System.out.println("学号" + "\t" + "年龄" + "\t" + "姓名");
                    System.out.println(s.getId() + "\t" + s.getAge() + "\t" + s.getName());
                    a = s.getXk();
                    print(a, e);
                }
            }
        }
    }

    public static void print(int[] a, ArrayList<Ex> e) {//打印
        int[] c;
        int t;
        for (int l = 1; l < 6; l++) {
            for (int i = 0; i < a.length; i++) {
                if (a[i] == l) {
                    t = l - 1;
                    Ex ex = e.get(t);
                    System.out.print(ex.getName() + "\t" + ex.getAddress() + "\t");
                    c = ex.getSalary();
                    for (int k = 0; k < c.length; k++) {//根据集合中的数字输出不同等级
                        if (c[k] == 1) {
                            System.out.print("优秀" + " ");
                        }
                        if (c[k] == 2) {
                            System.out.print("及格" + " ");
                        }
                        if (c[k] == 3) {
                            System.out.print("不及格" + " ");
                        }
                        if (k == c.length - 1) {
                            System.out.println();
                        }
                    }
                }
            }
            if (l == 5) {//适当转行保持美观
                System.out.println();
            }
        }
    }
}
